﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class addStu : Form
    {
        static SqlConnection con = new SqlConnection("server=.;database=C;pwd=123456;uid=sa;");
        static SqlCommand com;
        public addStu()
        {
            InitializeComponent();
        }

        private void label5_Click(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int sex = 1;
                com = new SqlCommand("insert into Student values(@Sid,@name,@StuSex,@StuAge,@StuClassID)", con);
                com.Parameters.AddWithValue("@Sid", Int32.Parse(textBox1.Text));
                com.Parameters.AddWithValue("@name", textBox2.Text);
                if (textBox3.Text == "男")
                {
                    sex = 1;
                }
                else { sex = 2; }
                com.Parameters.AddWithValue("@StuSex", sex);
                com.Parameters.AddWithValue("@StuAge", Int16.Parse(textBox4.Text));
                com.Parameters.AddWithValue("@StuClassID", Int16.Parse(textBox5.Text));
                con.Open();
                com.ExecuteNonQuery();

                MessageBox.Show("添加成功");
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message + "  请输入正确格式！");
            }
            this.Close();
            con.Close();
            Form1.bs = 1;
        }
    }
}
